package xyz.codingli.servlet;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;

/**
 * @author mizzle rain
 * @date 2021-01-09 16:16
 */
public class HelloWorldServlet extends HttpServlet {
    public HelloWorldServlet() {
        System.out.println(this + "执行了构造方法");
    }

    @Override
    public void init(ServletConfig config) throws ServletException {
        String author = config.getInitParameter("author");
        String site = config.getInitParameter("site");
        System.out.println(this + "执行了 init 方法");
        System.out.println("site = " + site);
        System.out.println("author = " + author);
    }

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        System.out.println(this + "执行了 doGet 方法");
        resp.getWriter().write("hello, world in javaweb project" + this.toString() +
                "name=" + req.getAttribute("name"));
    }

    @Override
    public void destroy() {
        System.out.println(this + "执行了 destroy 方法");
    }
}
